import {
  Table,
  Row,
  Col,
  Form,
  Input,
  Icon,
  InputNumber,
  Radio,
  DatePicker,
  Select,
  Upload,
  Button,
  Switch,
  Modal,
  Popconfirm,
  Tabs,
  message,
  Steps,
  Card,
  Tag,
} from 'antd';

import { FormComponentProps } from 'antd/es/form';
import React from 'react';
import SingleDragger from '../../../../../components/Commons/SingleDragger';
import { connect } from 'dva';
import Constants from '@/utils/Constants';
import Validator from '@/utils/Validator';
import CstForm from '../components/CstForm';
import { Banner10DataSource } from '@/components/portal/data.source';

const R = require('ramda');
const FormItem = Form.Item;
const RadioGroup = Radio.Group;

export default Form.create({ wrappedComponentRef: true })(
  class EditForm extends React.Component {
    constructor(props) {
      super(props);
      this.state = {
        open: false,
        disabled: '',
      };
    }

    componentDidMount() {
      if (R.equals(this.props.data.status)('1') || R.equals(this.props.data.status)('2')) {
        this.setState({ disabled: false });
      }
    }

    handleConfirm = () => {
      // let url = this.refs.unapprovalfile.getUrl();
      // if (R.isNil(url) || R.isEmpty(url)) {
      //   message.error("请先上传待审核单证");
      //   return;
      // }

      this.props.form.validateFields((errors, values) => {
        if (errors) return;

        // values.unapprovalfile = url;
        values.id = this.props.data.id;

        this.props.dispatch({
          type: 'manageEnterpriseMyEnterprise/updateCustomer',
          payload: {
            ...values,
            onSuccess: () => {
              this.props.handleGetUserInfos();
            },
          },
        });
        values;
        this.handleCancel();
      });
    };

    handleOpen = () => {
      this.setState({ open: true });
    };

    handleCancel = () => {
      this.props.form.resetFields();
      // if(this.refs.unapprovalfile)this.refs.unapprovalfile.resetUpload();
      this.props.handleCancel();
    };

    render() {
      const { getFieldDecorator } = this.props.form;
      let data = this.props.data;

      let disabledStatus = this.state.disabled;

      const formItemLayout = {
        labelCol: {
          xs: { span: 24 },
          sm: { span: 7 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 12 },
          md: { span: 10 },
        },
      };

      let confirm = false ? (
        ''
      ) : (
        <Button
          style={{ marginLeft: 10 }}
          type="primary"
          size="small"
          onClick={() => {
            this.handleConfirm(true);
          }}
        >
          保存
        </Button>
      );
      let cancel = false ? (
        ''
      ) : (
        <Button
          style={{ marginLeft: 10 }}
          type="primary"
          size="small"
          onClick={() => {
            this.handleCancel(true);
          }}
        >
          返回
        </Button>
      );

      return (
        <Card
          bordered={false}
          title={
            <span>
              {this.props.userInfo.entepriseName}
              <Tag color="red">{this.props.cstStatus}</Tag>
            </span>
          }
          extra={
            <span>
              {cancel}
              {confirm}
            </span>
          }
        >
          <Form style={{ marginTop: 8 }}>
            <CstForm parent={this.props} data={data} disabledStatus={disabledStatus} />
          </Form>
        </Card>
      );
    }
  },
);
// export default connect(({ global, loading }) => ({ global, loading }))(SingleDragger);
